package com.skyline.jfs.base.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.skyline.jfs.base.dao.AdminAdvanDao;
import com.skyline.jfs.base.model.Administrator;
import com.skyline.jfs.common.config.Config;

@Component("adminAdvanDao")
public class AdminAdvanDaoImpl implements AdminAdvanDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public void update(Administrator a) {
		// TODO Auto-generated method stub
		if (!a.getPassword().equals("")) {
			String sql = Config.getSql("AdminDao.updateWithPassowd");
			jdbcTemplate.update(sql, a.getJobNum(), a.getFirstName(),
					a.getLastName(), a.getDepartment(), a.getPosition(),
					a.getPhone(), a.getEmail(), a.getPassword(), a.getId());
		} else {
			String sql = Config.getSql("AdminDao.updateWithoutPassowd");
			jdbcTemplate.update(sql, a.getJobNum(), a.getFirstName(),
					a.getLastName(), a.getDepartment(), a.getPosition(),
					a.getPhone(), a.getEmail(), a.getId());
		}
	}

	@Override
	public void delete(Integer id) {
		String sql = Config.getSql("AdminDao.delete");
		jdbcTemplate.update(sql,id);
	}

	public void insertAdmin(Administrator a) {
		/*
		 * AdminBasicDao.insert=insert into
		 * Administrator(jobNum,firstName,lastName
		 * ,department,position,phone,email,password,exist)
		 * values(?,?,?,?,?,?,?,?,?,'true')
		 */
		String sql = Config.getSql("AdminDao.insert");
		jdbcTemplate.update(sql, a.getJobNum(), a.getFirstName(),
				a.getLastName(), a.getDepartment(), a.getPosition(),
				a.getPhone(), a.getEmail(), a.getPassword());
	}
}
